using System.Collections.Generic;
using UnityEngine;

public class MenuBackController : MonoBehaviour
{
	public static MenuBackController instance;


	public MenuUIState curstate;

	public List<MenuUIState> prestate;

	private void Awake()
	{
		if (instance == null)
		{
			instance = this;
		}
	}

	private void Update()
	{
		if (UnityEngine.Input.GetKeyUp(KeyCode.Escape))
		{
			BackFun();
		}
	}

	public void BackFun()
	{
		if (GlobalInf.menuuifirst)
		{
			return;
		}
		switch (curstate)
		{
			case MenuUIState.loading:
				break;
			case MenuUIState.hitinfoui:
			case MenuUIState.openboxui:
				break;
			case MenuUIState.getreward:
				break;
			case MenuUIState.mainui:
				MenuUIController.instance.enable_exitui();
				break;
			case MenuUIState.garageui:
				MenuUIController.instance.disable_garage(isres: true);
				MenuUIController.instance.show_planetime();
				MenuUIController.instance.enable_mainui();
				break;
			case MenuUIState.chargeui:
				MenuUIController.instance.disable_chargeui();
				break;
			case MenuUIState.challengeui:
				MenuUIController.instance.disable_challengeui();
				MenuUIController.instance.show_planetime();
				MenuUIController.instance.enable_mainui();
				break;
			case MenuUIState.battleui:
				MenuUIController.instance.disable_battleui();
				MenuUIController.instance.show_planetime();
				MenuUIController.instance.enable_mainui();
				break;
			case MenuUIState.levelui:
				MenuUIController.instance.disable_levelui();
				MenuUIController.instance.battleui.enable();
				break;
			case MenuUIState.startui:
				MenuUIController.instance.disable_startui();
				break;
			case MenuUIState.rewardui:
				MenuUIController.instance.disable_rewardui();
				MenuUIController.instance.show_planetime();
				MenuUIController.instance.enable_mainui();
				break;
			case MenuUIState.upgradeui:
				MenuUIController.instance.disable_upgradeui();
				MenuUIController.instance.enable_garage(0);
				break;
			case MenuUIState.confirm_buyplane:
				MenuUIController.instance.garageui.confirmClose();
				break;
			case MenuUIState.confirm_unlocklevel:
				MenuUIController.instance.battleui.confirmClose();
				break;
			case MenuUIState.showplaneui:
				MenuUIController.instance.garageui.backshowarea(null);
				break;
			case MenuUIState.showpieceui:
				MenuUIController.instance.disable_pieceui();
				break;
			case MenuUIState.showjunxian:
				MenuUIController.instance.disable_junxianui();
				break;
            case MenuUIState.showprivacy:
                MenuUIController.instance.disable_privacyui();
                break;
            case MenuUIState.getpiece:
				MenuUIController.instance.disable_getpieceui();
				break;
			case MenuUIState.challinfo:
				MenuUIController.instance.disable_challinfoui();
				break;
			case MenuUIState.exitui:
				if (Platform.IsFullScreenSmallShowing())
				{
					Platform.HideFullScreenSmall();
				}
				else
				{
					MenuUIController.instance.disable_exitui();
				}
				break;
			case MenuUIState.bonusui:
				MenuUIController.instance.disable_dailybonusui();
				break;
			case MenuUIState.optionui:
				MenuUIController.instance.disable_optionui();
				break;
			case MenuUIState.creditsui:
				MenuUIController.instance.disable_creditsui();
				break;
			case MenuUIState.sale1:
				MenuUIController.instance.disable_saleui1();
				break;
			case MenuUIState.sale2:
				MenuUIController.instance.disable_saleui2();
				break;
			case MenuUIState.boxinfo:
				MenuUIController.instance.disable_boxinfoui();
				break;
		}
	}

	public void HomeFun()
	{
		if (curstate != MenuUIState.mainui)
		{
			MonoInstance<AudioController>.instance.play(AudioType.UI_BTN, 0f);
		}
		while (curstate != MenuUIState.mainui)
		{
			BackFun();
		}
	}

	public void StroeGoFun()
	{
		if (curstate == MenuUIState.garageui)
		{
			return;
		}
		MonoInstance<AudioController>.instance.play(AudioType.UI_BTN, 0f);
		while (curstate != MenuUIState.mainui)
		{
			BackFun();
			if (curstate == MenuUIState.garageui)
			{
				return;
			}
		}
		if (curstate == MenuUIState.mainui)
		{
			MenuUIController.instance.mainui.OnClickstoreBtn(null);
		}
	}

	public void ChangeMenuUIstate(MenuUIState newstate)
	{
		MenuUIController.instance.effectui.clear();
		if (curstate == MenuUIState.confirm_buyplane)
		{
			curstate = newstate;
		}
		else if (curstate == MenuUIState.confirm_unlocklevel)
		{
			curstate = newstate;
		}
		else
		{
			if (curstate == newstate)
			{
				return;
			}
			if (prestate.Count > 0)
			{
				if (prestate[prestate.Count - 1] != curstate)
				{
					prestate.Add(curstate);
				}
			}
			else
			{
				prestate.Add(curstate);
			}
			curstate = newstate;
		}
	}

	public void BackMenuUIstate()
	{
		if (prestate.Count > 0)
		{
			curstate = prestate[prestate.Count - 1];
			prestate.RemoveAt(prestate.Count - 1);
			MenuUIController.instance.effectui.clear();
		}
	}

	private void OnDestroy()
	{
		if (instance != null)
		{
			instance = null;
		}
	}
}
